/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ec.cd.server.gui;

import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.traces.Trace2DLtd;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JPanel;

/**
 *
 * @author endri
 */
public class GraphFrame extends javax.swing.JFrame {

    private Chart2D graphAcc, graphGyr, graphState;
    private ITrace2D traceAccX, traceAccY, traceAccZ, traceGyrX, traceGyrY, traceGyrZ, traceState;

    private int numMsg = 0;
    /**
     * Creates new form GraphFrame
     */
    public GraphFrame(String clientName) {
        initComponents();
        this.setTitle("Client: " + clientName);
        
        initializeGraphs();
    }

    /**
     *
     */
    public void initializeGraphs() {
        graphAcc = new Chart2D();
        graphGyr = new Chart2D();
        graphState = new Chart2D();
        traceAccX = new Trace2DLtd(200);
        getTraceAccX().setColor(Color.RED);
        getTraceAccX().setPhysicalUnits("Message Number", "Tilt degrees");
        traceAccY = new Trace2DLtd(200);
        getTraceAccY().setColor(Color.GREEN);
        getTraceAccY().setPhysicalUnits("Message Number", "Tilt degrees");
        traceAccZ = new Trace2DLtd(200);
        getTraceAccZ().setColor(Color.BLUE);
        getTraceAccZ().setPhysicalUnits("Message Number", "Tilt degrees");
        traceGyrX = new Trace2DLtd(200);
        getTraceGyrX().setColor(Color.RED);
        getTraceGyrX().setPhysicalUnits("Message Number", "Degrees/sec");
        traceGyrY = new Trace2DLtd(200);
        getTraceGyrY().setColor(Color.green);
        getTraceGyrY().setPhysicalUnits("Message Number", "Degrees/sec");
        traceGyrZ = new Trace2DLtd(200);
        getTraceGyrZ().setColor(Color.blue);
        getTraceGyrZ().setPhysicalUnits("Message Number", "Degrees/sec");
        traceState = new Trace2DLtd(200);
        getTraceState().setPhysicalUnits("Message Number", "State");
        getGraphAcc().addTrace(getTraceAccX());
        getGraphAcc().addTrace(getTraceAccY());
        getGraphAcc().addTrace(getTraceAccZ());
        getGraphGyr().addTrace(getTraceGyrX());
        getGraphGyr().addTrace(getTraceGyrY());
        getGraphGyr().addTrace(getTraceGyrZ());
        getGraphState().addTrace(getTraceState());
        JPanel panelAcc = new JPanel(new GridLayout(1, 1));
        JPanel panelGyr = new JPanel(new GridLayout(1, 1));
        JPanel panelStates = new JPanel(new GridLayout(1, 1));
        panelAcc.setSize(200,200);
        panelGyr.setSize(200,200);
        panelStates.setSize(200,200);
        panelAcc.add(graphAcc);
        panelGyr.add(graphGyr);
        panelStates.add(graphState);
        panelGraphs.setLayout(new GridLayout(3, 1));
        panelGraphs.add(panelAcc);
        panelGraphs.add(panelGyr);
        panelGraphs.add(panelStates);
        
        this.getContentPane().setLayout(new GridLayout(2, 1));
        this.getContentPane().add(panelGraphs);
        this.getContentPane().add(jPanel1);
    }

    public void setRanges(float[] accRanges, float[] gyrRanges) {
        lblTiltXMin.setText(new Float( accRanges[0] ).toString());
        lblTiltXMax.setText(new Float( accRanges[1] ).toString());
        lblTiltYMin.setText(new Float( accRanges[2] ).toString());
        lblTiltYMax.setText(new Float( accRanges[3] ).toString());
        lblTiltZMin.setText(new Float( accRanges[4] ).toString());
        lblTiltZMax.setText(new Float( accRanges[5] ).toString());
        lblGyrXMin.setText(new Float(gyrRanges[0]).toString());
        lblGyrXMax.setText(new Float(gyrRanges[1]).toString());
        lblGyrYMin.setText(new Float(gyrRanges[2]).toString());
        lblGyrYMax.setText(new Float(gyrRanges[3]).toString());
        lblGyrZMin.setText(new Float(gyrRanges[4]).toString());
        lblGyrZMax.setText(new Float(gyrRanges[5]).toString());        
    }
    
    public void setState(String state)
    {
        lblState.setText(state);
    }
    
    public void increaseNumMsg()
    {
        numMsg+=1;
        lblNumMsg.setText(new Integer(numMsg).toString());
    }
    
    public static void main(String args[]){
        GraphFrame graphFrame = new GraphFrame("");
        graphFrame.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblTiltXMin = new javax.swing.JLabel();
        lblTiltXMax = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblTiltYMin = new javax.swing.JLabel();
        lblTiltYMax = new javax.swing.JLabel();
        lblTiltZMax = new javax.swing.JLabel();
        lblTiltZMin = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblGyrXMin = new javax.swing.JLabel();
        lblGyrXMax = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblGyrYMin = new javax.swing.JLabel();
        lblGyrYMax = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        lblGyrZMin = new javax.swing.JLabel();
        lblGyrZMax = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        lblNumMsg = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lblState = new javax.swing.JLabel();
        panelGraphs = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.FlowLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));

        jLabel2.setText("Tilt:");

        jLabel1.setText("Ranges:");

        jLabel3.setText("X");

        lblTiltXMin.setText("(min)");

        lblTiltXMax.setText("(max)");

        jLabel4.setText("Y");

        lblTiltYMin.setText("(min)");

        lblTiltYMax.setText("(max)");

        lblTiltZMax.setText("(max)");

        lblTiltZMin.setText("(min)");

        jLabel5.setText("Z");

        jLabel6.setText("Gyro:");

        jLabel7.setText("X");

        lblGyrXMin.setText("(min)");

        lblGyrXMax.setText("(max)");

        jLabel8.setText("Y");

        lblGyrYMin.setText("(min)");

        lblGyrYMax.setText("(max)");

        jLabel9.setText("Z");

        lblGyrZMin.setText("(min)");

        lblGyrZMax.setText("(max)");

        jLabel10.setText("Messages received:");

        lblNumMsg.setText("(num)");

        jLabel11.setText("Current State:");

        lblState.setText("(state)");
        lblState.setToolTipText("");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTiltXMin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTiltXMax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTiltYMin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTiltYMax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTiltZMin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTiltZMax))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblGyrXMin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblGyrXMax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblGyrYMin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblGyrYMax)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblGyrZMin)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblGyrZMax))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblNumMsg))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblState)))
                .addContainerGap(173, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(lblTiltXMin)
                    .addComponent(lblTiltXMax)
                    .addComponent(jLabel4)
                    .addComponent(lblTiltYMin)
                    .addComponent(lblTiltYMax)
                    .addComponent(jLabel5)
                    .addComponent(lblTiltZMin)
                    .addComponent(lblTiltZMax))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addComponent(lblGyrXMin)
                    .addComponent(lblGyrXMax)
                    .addComponent(jLabel8)
                    .addComponent(lblGyrYMin)
                    .addComponent(lblGyrYMax)
                    .addComponent(jLabel9)
                    .addComponent(lblGyrZMin)
                    .addComponent(lblGyrZMax))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(lblNumMsg))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(lblState))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1);

        javax.swing.GroupLayout panelGraphsLayout = new javax.swing.GroupLayout(panelGraphs);
        panelGraphs.setLayout(panelGraphsLayout);
        panelGraphsLayout.setHorizontalGroup(
            panelGraphsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        panelGraphsLayout.setVerticalGroup(
            panelGraphsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        getContentPane().add(panelGraphs);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblGyrXMax;
    private javax.swing.JLabel lblGyrXMin;
    private javax.swing.JLabel lblGyrYMax;
    private javax.swing.JLabel lblGyrYMin;
    private javax.swing.JLabel lblGyrZMax;
    private javax.swing.JLabel lblGyrZMin;
    private javax.swing.JLabel lblNumMsg;
    private javax.swing.JLabel lblState;
    private javax.swing.JLabel lblTiltXMax;
    private javax.swing.JLabel lblTiltXMin;
    private javax.swing.JLabel lblTiltYMax;
    private javax.swing.JLabel lblTiltYMin;
    private javax.swing.JLabel lblTiltZMax;
    private javax.swing.JLabel lblTiltZMin;
    private javax.swing.JPanel panelGraphs;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the traceAccX
     */
    public ITrace2D getTraceAccX() {
        return traceAccX;
    }

    /**
     * @return the traceAccY
     */
    public ITrace2D getTraceAccY() {
        return traceAccY;
    }

    /**
     * @return the traceAccZ
     */
    public ITrace2D getTraceAccZ() {
        return traceAccZ;
    }

    /**
     * @return the traceGyrX
     */
    public ITrace2D getTraceGyrX() {
        return traceGyrX;
    }

    /**
     * @return the traceGyrY
     */
    public ITrace2D getTraceGyrY() {
        return traceGyrY;
    }

    /**
     * @return the traceGyrZ
     */
    public ITrace2D getTraceGyrZ() {
        return traceGyrZ;
    }

    /**
     * @return the traceState
     */
    public ITrace2D getTraceState() {
        return traceState;
    }

    /**
     * @return the graphAcc
     */
    public Chart2D getGraphAcc() {
        return graphAcc;
    }

    /**
     * @return the graphGyr
     */
    public Chart2D getGraphGyr() {
        return graphGyr;
    }

    /**
     * @return the graphState
     */
    public Chart2D getGraphState() {
        return graphState;
    }
}
